﻿package src {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	import flash.ui.Mouse;
	import flash.system.fscommand;
	
	public class MsgMenu extends MovieClip {
		
		private var par:Bat;
		private var myType:String;
		
		public function MsgMenu(myParent:Bat, type:String) {
			
			addEventListener(Event.ADDED_TO_STAGE,init);
			par=myParent;
			myType=type;
		
		}
		
		private function init(e:Event){
			removeEventListener(Event.ADDED_TO_STAGE,init);
			
			myText.multiline = true;
			myText.wordWrap = true;
			stage.addEventListener(KeyboardEvent.KEY_DOWN,onPress);
			
			switch (myType){
				case "Instructions":
					myTitle.text="Instrucciones";
					myText.text="Presiona las teclas direccionales para mover al murciélago y las teclas QWER para responder las preguntas. Responde las preguntas para ver mejor y come moscas para obtener puntaje.";
					break;
				case "Results":
					myTitle.text="Resultados";
					if (par.game.fliesEaten==0){myText.text="No comiste ni una mosca."
					} else if (par.game.fliesEaten==1){myText.text="Comiste una sola mosca."
					} else {myText.text="¡Bien Hecho! Comiste "+par.game.fliesEaten.toString()+" moscas."}
					break;
			}
			
			acceptButton.letter.text= "J";
			acceptButton.myText.text= "Jugar";
			acceptButton.buttonMode=true;
			acceptButton.useHand=true;
			acceptButton.addEventListener(MouseEvent.CLICK,acceptButtonPressed);
			
			exitButton.letter.text= "X";
			exitButton.myText.text= "Salir";
			exitButton.addEventListener(MouseEvent.CLICK,exitButtonPressed);
			exitButton.buttonMode=true;
			exitButton.useHand=true;
			
			bestScore.text="Mejor Puntaje: "+par.game_files.data.bestScore.toString();
			
		}
		
		private function onPress(e:KeyboardEvent){
			switch (e.keyCode){
				case "J": trace("Play pressed");
					par.initGame();			
					removeEventListener(MouseEvent.CLICK,acceptButtonPressed);
					removeEventListener(KeyboardEvent.KEY_DOWN,onPress); break;
				case "X": trace(" Exit pressed");
					removeEventListener(MouseEvent.CLICK,acceptButtonPressed);
					removeEventListener(KeyboardEvent.KEY_DOWN,onPress);
					fscommand("quit"); break;
			}
		}
		
		private function acceptButtonPressed(e:Event){
			trace("Play pressed");
			par.initGame();			
			removeEventListener(MouseEvent.CLICK,acceptButtonPressed);
			removeEventListener(KeyboardEvent.KEY_DOWN,onPress);			
		}
		
		private function exitButtonPressed(e:Event){
			trace(" Exit pressed");
			removeEventListener(MouseEvent.CLICK,acceptButtonPressed);
			removeEventListener(KeyboardEvent.KEY_DOWN,onPress);
			fscommand("quit");			
		}
		
	}
	
}
